﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShangChuan.aspx.cs" Inherits="Lian_AiXiou.ShangChuan" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
                <div>视频录制</div>
                <span id="file_video_btn">选择视频<input type="file" name="file_video" id="file_video" accept="video/*" /></span>
                <input type="text" id="biao" />
                <input type="button" onclick="aaa()" value="000" />
        </div>
    </form>
</body>
    <script src="Scripts/jquery-3.4.1.min.js"></script>
    <script src="Scripts/lib/es6-promise.min.js"></script>
    <script src="Scripts/lib/aliyun-oss-sdk-6.13.0.min.js"></script>
    <script src="Scripts/aliyun-upload-sdk-1.5.2.min.js"></script>
    <script type="text/javascript">
        function aaa() {
            var file = document.querySelector('#file_video').files[0];
            var biao = $("#biao").val();
            if (!file) {
                alert('请拍摄视频！');
                return;
            }
            var filename = document.querySelector('#file_video').value;/*上传视频的file*/
            var userData = '{"Vod":{}}';
            // 请求上传凭证
            var params = {
                filename: encodeURIComponent(filename),
                biao:biao
            }
            //data 一般处理程序后调用的方法
            $.get('/yiban/VideoUploadHandler.ashx', params, function (data) {
                var res = eval('(' + data + ')');
                uploader = createUploader(res.VideoId, res.UploadAddress, res.UploadAuth);
                // 添加视频
                uploader.addFile(file, null, null, null, userData);
                    uploader.startUpload();
            })
        }
        function createUploader(videoId, uploadAddress, uploadAuth) {
            var uploader = new AliyunUpload.Vod({
                userId: '<% = ConfigurationManager.AppSettings["aliyun:UserId"] %>',    // 阿里账号ID
                region: '<% = ConfigurationManager.AppSettings["aliyun:RegionId"] %>',  // 上传到视频点播的地域
                partSize: 1048576,      // 分片大小默认10MB
                // 添加文件成功
                addFileSuccess: function (uploadInfo) {
                    //console.log('添加文件成功，等待上传...');
                },
                // 开始上传
                onUploadstarted: function (uploadInfo) {
                    uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId);
                    //console.log('开始上传');
                },
                // 上传成功
                onUploadSucceed: function (uploadInfo) {
                    //console.log('上传成功');
                    alert('上传成功');
                    window.location.href = '/Default.aspx';
                },
                // 文件上传失败
                onUploadFailed: function (uploadInfo, code, message) {
                    //console.log('上传失败');
                    alert(message + ' 错误码：' + code);
                },
                // 文件上传进度
                onUploadProgress: function (uploadInfo, totalSize, loadedPercent) {
                    //console.log('上传进度' + loadedPercent);
                    app.progressbar.set('#upload-progressbar', loadedPercent * 100);
                }
            })
            return uploader;
        }
    </script>
</html>
